package org.academic.texteditor.gui.plugin.document;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;

import org.academic.texteditor.gui.PrincipalWindow;
import org.academic.texteditor.gui.component.PageContainer;
import org.academic.texteditor.gui.component.menu.MenuFactory;
import org.academic.texteditor.gui.component.toolbar.ToolBarFactory;
import org.academic.texteditor.gui.form.PageContainerForm;
import org.academic.texteditor.gui.plugin.BasePlugin;

public class NewDocumentPlugin extends BasePlugin {

	private static final long serialVersionUID = 7599132008526800360L;
	
	public NewDocumentPlugin() {
		super("newDocumentPlugin");
	}

	@Override
	public void initialize(PageContainer pageContainer) {
		JMenu menu = MenuFactory.getApplication();
		MenuFactory.createMenuItem(menu, 0, "new", "menu.application.new", this).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));;
		menu.setVisible(true);
		
		JToolBar main = ToolBarFactory.getMain();
		ToolBarFactory.createButton(main, "new", 0, "toolbar.main.new", "images/new-icon.png", this);
	}
	
	@Override
	public void activate() {
		
	}

	@Override
	public void execute() {
		PrincipalWindow.getInstance().openWindow(new PageContainerForm());
	}
	
	@Override
	public void deactivate() {

	}

	@Override
	public void destroy() {
		JMenu menu = MenuFactory.getApplication();
		MenuFactory.removeMenuItem(menu, "new");
		
		JToolBar main = ToolBarFactory.getMain();
		ToolBarFactory.removeButton(main, "new");
	}

}
